# -*- coding: UTF-8 -*-
from typing import List
from leetcode_helper import TestcaseHelper, SolutionBase


class Solution(SolutionBase):
    # 解题的方法，命名和Leetcode的保持一致即可
    def maxScoreIndices(self, nums: List[int]) -> List[int]:
        ans = []

        count = len(nums)
        sum_one = sum(nums)
        sum_zero = count - sum_one
        max_score = 0

        if sum_one > sum_zero:
            ans.append(0)
            max_score = sum_one
        elif sum_one < sum_zero:
            max_score = sum_zero
        else:
            max_score = sum_one
            ans.append(0)
        temp_sum = 0

        for i in range(len(nums)):
            temp_sum += nums[i]
            score_left = i + 1 - temp_sum
            score_right = sum_one - temp_sum

            score = score_left + score_right
            if max_score == score:
                ans.append(i + 1)
            elif score > max_score:
                ans = [i + 1]
                max_score = score

        return ans


if __name__ == '__main__':


    # 按照leetcode的题目说明，将基本的test case填入
    # 每条case的最后一个元素是正确的结果，即期待的结果
    # 使用元组来保存输入的数据，期待的结果
    testcases = [
        ([1, 0, 0, 1,1,1,1], [3]),
        ([0, 0, 1, 0], [2, 4])
    ]

    for case_item in testcases:
        solution = Solution()
        # 获取测试用的case和期待的执行结果
        # TODO: 单独一条的Test case的组成随题目的不同而改变，需要按照题目来修改代码
        input1 = case_item[0]
        expect = case_item[len(case_item) - 1]
        # TODO: 调用对应方法，需要替换具体的方法
        exec_result = solution.maxScoreIndices(input1)

        # 判断执行结果，输出提示信息
        check_result = solution.check_result(expect, exec_result)
        TestcaseHelper.print_case(check_result, case_item, exec_result)

